home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1989, 1990 Aladdin Enterprises. All rights reserved.
- Distributed by Free Software Foundation, Inc.
-
- This file is part of Ghostscript.
-
- Ghostscript is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
- to anyone for the consequences of using it or for whether it serves any
- particular purpose or works at all, unless he says so in writing. Refer
- to the Ghostscript General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- Ghostscript, but only under the conditions described in the Ghostscript
- General Public License. A copy of this license is supposed to have been
- given to you along with Ghostscript so you can know your rights and
- responsibilities. It should be in a file named COPYING. Among other
- things, the copyright notice and this notice must be preserved on all
- copies. */
-
- /* gdevpcfb.h */
- /* Common parts of IBM PC-compatible display drivers for GhostScript. */
- /* This is fundamentally an EGA driver with some parameters */
- /* that allow it to drive larger displays. */
- /*
- * >>>>>> NOTE: the following must be defined before #include'ing this file:
- * >>>>>> DEVICE_STRUCT_NAME, DEVICE_NAME, FB_RASTER, SCREEN_HEIGHT,
- * >>>>>> SCREEN_ASPECT_RATIO, VIDEO_MODE
- */
- /* Note that this header file includes executable code, */
- /* and assumes an ANSI-compatible compiler. */
- #define interrupt /* patch ANSI incompatibility */
- #include <dos.h>
- typedef union REGS registers;
- #include "gs.h"
- #include "gsmatrix.h" /* for gxdevice.h */
- #include "gxbitmap.h"
- #include "gxdevice.h"
-
- /* Define the short (integer) version of "transparent" color. */
- /* ****** Depends on gx_no_color_index being all 1's. ******/
- #define no_color ((int)gx_no_color_index)
-
- /* For testing, the EGA may be defined as a monochrome, 8-color, or */
- /* 16-color device. */
- #define ega_bits_of_color 2 /* 0, 1, or 2 */
-
- /* Dimensions of screen */
- #define screen_size_x (FB_RASTER * 8)
- #define screen_size_y SCREEN_HEIGHT
- /* Other display parameters */
- #define raster_x FB_RASTER
- #define aspect_ratio SCREEN_ASPECT_RATIO
- #define graphics_video_mode VIDEO_MODE
- /* Range of r-g-b values */
- #define rgb_max (ega_bits_of_color == 1 ? 1 : 3)
-
- /* Typedef for the device structure */
- typedef struct gx_device_s gx_device;
-
- /* Procedures */
-
- /* See gxdevice.h for the definitions of the procedures. */
-
- dev_proc_open_device(ega_open);
- dev_proc_close_device(ega_close);
- dev_proc_map_rgb_color(ega_map_rgb_color);
- dev_proc_map_color_rgb(ega_map_color_rgb);
- dev_proc_fill_rectangle(ega_fill_rectangle);
- dev_proc_tile_rectangle(ega_tile_rectangle);
- int ega_write_dot(P4(gx_device *, int, int, gx_color_index));
- dev_proc_copy_mono(ega_copy_mono);
- dev_proc_copy_color(ega_copy_color);
-
- /* The device descriptor */
- private gx_device_procs ega_procs = {
- ega_open,
- gx_default_get_initial_matrix,
- gx_default_sync_output,
- gx_default_output_page,
- ega_close,
- ega_map_rgb_color,
- ega_map_color_rgb,
- ega_fill_rectangle,
- ega_tile_rectangle,
- ega_copy_mono,
- ega_copy_color,
- gx_default_draw_line,
- gx_default_fill_trapezoid,
- gx_default_tile_trapezoid
- };
- gx_device DEVICE_STRUCT_NAME = {
- sizeof(gx_device),
- &ega_procs,
- DEVICE_NAME,
- screen_size_x, screen_size_y,
- /* The following parameters map an appropriate fraction of */
- /* the screen to an 8.5" x 11" coordinate space. */
- /* This may or may not be what is desired! */
- (screen_size_y * aspect_ratio) / 11.0, /* x density */
- screen_size_y / 11.0, /* y density */
- (ega_bits_of_color ? 1 : 0), /* has_color */
- rgb_max,
- 4, /* bits per color pixel */
- 0 /* not opened yet */
- };
-
- /* Define the color spectrum */
- #define black 0
- #define blue 1
- #define green 2
- #define cyan 3
- #define red 4
- #define magenta 5
- #define brown 6
- #define white 7
- #define dgray 8 /* dark gray is not very usable */
- #define lblue 9
- #define lgreen 10
- #define lcyan 11
- #define lred 12
- #define lmagenta 13
- #define yellow 14
- #define bwhite 15
-
- /* Forward declarations */
- private int ega_get_mode();
- private void ega_set_mode(int);
-
- /* Save the EGA mode */
- private int ega_save_mode = -1;
-
- /* Reinitialize the EGA for text mode */
- int
- ega_close(gx_device *dev)
- { if ( ega_save_mode >= 0 ) ega_set_mode(ega_save_mode);
- return 0;
- }
-
- /* Map a r-g-b color to an EGA color code. */
- /* r, g, b are 0..3. */
- private char mono_color[4] =
- { black, dgray, white, bwhite };
- gx_color_index
- ega_map_rgb_color(gx_device *dev, ushort r, ushort g, ushort b)
- {
- #ifdef DEBUG
- if ( r > rgb_max || g > rgb_max || b > rgb_max )
- { eprintf3("Bad rgb values! %ud, %ud, %ud\n", r, g, b);
- exit(1);
- }
- #endif
- #if ega_bits_of_color == 0
- return (gx_color_index)mono_color[((r * 3) + (g * 6) + b) >> 3];
- #else
- # if ega_bits_of_color == 1
- return (gx_color_index)
- ((r << 2) + (g << 1) + b +
- ((r | b) << 3));
- # else
- return (gx_color_index)
- (((r & 2) << 1) + (g & 2) + ((b & 2) >> 1) +
- (((r & b | g) & 1) << 3));
- # endif
- #endif
- }
-
- /* Map a color code to r-g-b. Surprisingly enough, this is algorithmic. */
- int
- ega_map_color_rgb(gx_device *dev, gx_color_index color, ushort *prgb)
- {
- #define icolor (int)color
- #if rgb_max > 1
- int aux = (icolor >> 3) & 1;
- prgb[0] = ((icolor >> 1) & 2) + aux;
- prgb[1] = (icolor & 2) + aux;
- prgb[2] = ((icolor << 1) & 2) + aux;
- #else
- prgb[0] = icolor >> 2;
- prgb[1] = (icolor >> 1) & 1;
- prgb[2] = icolor & 1;
- #endif
- return 0;
- #undef icolor
- }
-
- /* Macro for validating dot parameters x, y, color */
- #define validate_dot()\
- if ( (unsigned)x >= (unsigned)(dev->width) ||\
- (unsigned)y >= (unsigned)(dev->height) ||\
- (unsigned)color > 0xf )\
- return -1
-
- /* Macro for validating rectangle parameters x, y, w, h */
- #define validate_rect()\
- if ( w <= 0 || h <= 0 ) return 0;\
- if ( x < 0 || y < 0 || x + w > dev->width || y + h > dev->height ) return -1
-
- /* ------ Internal routines ------ */
-
- /* Read the device mode */
- private int
- ega_get_mode()
- { registers regs;
- regs.h.ah = 0xf;
- int86(0x10, ®s, ®s);
- return regs.h.al;
- }
-
- /* Set the device mode */
- private void
- ega_set_mode(int mode)
- { registers regs;
- regs.h.ah = 0;
- regs.h.al = mode;
- int86(0x10, ®s, ®s);
- }
-